<div class="content-wrapper">
    <section class="content-header">
        <h1>{$billInfo?'编辑':'申请'}发票</h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">订单管理</li>
            <li class="active"><a href="/admin/order/salesmanOrderList">订单列表</a></li>
            <li class="active">{$billInfo?'编辑':'申请'}发票</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
            </div>
            <div class="box-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-6">
                                <input type="hidden" name="bill_id" id="bill_id" value="{$billInfo.id}" />
                                <input type="hidden" name="order_id" id="order_id" value="{$orderInfo.id}" />
                                <input type="hidden" name="admin_id" id="admin_id" value="{$orderInfo.admin_id}" />
                                <div class="form-group">
                                    <label for="admin_name" class="col-sm-3 control-label"> 业务员 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="业务员" id="admin_name" name="admin_name" value="{$orderInfo.admin_name}" disabled readonly>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="order_rate" class="col-sm-3 control-label"> 订单占比 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="订单占比" id="order_rate" name="order_rate" value="{$billInfo.order_rate}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="item_type" class="col-sm-3 control-label"> 产品类型 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="贴吧运营or文字直播" id="item_type" name="item_type" value="{$billInfo.item_type}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="item_name" class="col-sm-3 control-label"> 客户产品 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="产品名称" id="item_name" name="item_name" value="{$billInfo.item_name}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="protocol_number" class="col-sm-3 control-label"> 协议号 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="协议号" id="protocol_number" name="protocol_number" value="{$billInfo.protocol_number}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="is_filing" class="col-sm-3 control-label"> 合同归档 </label>
                                    <div class="col-sm-8">
                                        <select class="form-control" id="is_filing" name="is_filing">
                                            <option value="0" <if condition="$billInfo.is_filing eq 0 ">selected</if>>未归档</option>
                                            <option value="1" <if condition="$billInfo.is_filing eq 1 ">selected</if>>已归档</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="company_title" class="col-sm-3 control-label">开票公司抬头 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="开票公司抬头" id="company_title" name="company_title" value="{$billInfo.company_title}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="arrival_time" class="col-sm-3 control-label">提前开票到款时间 </label>
                                    <div class="col-sm-8 date">
                                        <input type="text" class="form-control" placeholder="2017-12-25" id="arrival_time" name="arrival_time" value="{$billInfo.arrival_time|date='Y-m-d',###}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="type" class="col-sm-3 control-label">发票类型 </label>
                                    <div class="col-sm-8">
                                        <select class="form-control" id="type" name="type">
                                            <option value="0">请选择</option>
                                            <foreach name="bill_typeList" item="b_val" key="b_key">
                                                <option value="{$b_key}" <if condition="$billInfo.type eq $b_key">selected</if>>{$b_val}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="amount" class="col-sm-3 control-label">开票金额 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="0.00" id="amount" name="amount" value="{$billInfo.amount}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="description" class="col-sm-3 control-label">开票内容 </label>
                                    <div class="col-sm-8">
                                        <textarea type="text" class="form-control" placeholder="开票内容" id="description" name="description" rows="5">{$billInfo.description}</textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="bill_title" class="col-sm-3 control-label">发票抬头 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="发票抬头" id="bill_title" name="bill_title" value="{$billInfo.bill_title}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="send_type" class="col-sm-3 control-label">寄送方式 </label>
                                    <div class="col-sm-8">
                                        <select class="form-control" id="send_type" name="send_type">
                                            <option value="0">请选择</option>
                                            <option value="1" <if condition="$billInfo.send_type eq 1 ">selected</if>>自取</option>
                                            <option value="2" <if condition="$billInfo.send_type eq 2 ">selected</if>>邮寄</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="send_address" class="col-sm-3 control-label">邮寄地址 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="邮寄地址" id="send_address" name="send_address" value="{$billInfo.send_address}">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="taxpayer_id_number" class="col-sm-3 control-label">纳税人识别号 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="纳税人识别号" id="taxpayer_id_number" name="taxpayer_id_number" value="{$billInfo.taxpayer_id_number}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="address" class="col-sm-3 control-label">地址 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="地址" id="address" name="address" value="{$billInfo.address}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="bank" class="col-sm-3 control-label">开户行 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="开户行" id="bank" name="bank" value="{$billInfo.bank}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="bank_account" class="col-sm-3 control-label">银行账号 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="银行账号" id="bank_account" name="bank_account" value="{$billInfo.bank_account}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="mobile" class="col-sm-3 control-label">联系电话 </label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="联系电话" id="mobile" name="mobile" value="{$billInfo.mobile}">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="form-field-1" class="col-sm-5 control-label"></label>
                        <div class="col-sm-5">
                            <button type="button" class="btn btn-info btn-sm save-btn">提交</button>
                            &nbsp;
                            <button type="reset" class="btn btn-sm">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script type="application/javascript">
    $(function () {
        //Date picker
        $('#arrival_time').datepicker({
            startDate: new Date(),
            language: 'zh-CN',
            format:'yyyy-mm-dd',
            todayHighlight: true,
            autoclose: true
        });
    });

    //保存
    $(".save-btn").click(function(){
        var bill_id = $("#bill_id").val();
        var order_id = $("#order_id").val();
        var admin_id = $("#admin_id").val();
        var order_rate = $("#order_rate").val();
        var company_title = $("#company_title").val();
        var bill_title = $("#bill_title").val();
        var protocol_number = $("#protocol_number").val();
        var is_filing = $("#is_filing").val();
        var type = $("#type").val();
        var item_name = $("#item_name").val();
        var item_type = $("#item_type").val();
        var arrival_time = $("#arrival_time").val();
        var amount = $("#amount").val();
        var description = $("#description").val();
        var send_type = $("#send_type").val();
        var taxpayer_id_number = $("#taxpayer_id_number").val();
        var address = $("#address").val();
        var send_address = $("#send_address").val();
        var bank = $("#bank").val();
        var bank_account = $("#bank_account").val();
        var mobile = $("#mobile").val();

        if(order_rate == '') {
            layer.msg('请填写订单占比',{time: 1000});
            $("#order_rate").focus();
            return false;
        }
        if(company_title == '') {
            layer.msg('请填写开票公司台头',{time: 1000});
            $("#company_title").focus();
            return false;
        }
        if(bill_title == '') {
            layer.msg('请填写发票抬头',{time: 1000});
            $("#bill_title").focus();
            return false;
        }
        if(protocol_number == '') {
            layer.msg('请填写协议号',{time: 1000});
            $("#protocol_number").focus();
            return false;
        }
        if(item_name == '') {
            layer.msg('请填写客户推广产品',{time: 1000});
            $("#item_name").focus();
            return false;
        }
        if(item_type == '') {
            layer.msg('请填写产品类型',{time: 1000});
            $("#item_type").focus();
            return false;
        }
        if(arrival_time == '') {
            layer.msg('请填写预计到账时间',{time: 1000});
            $("#arrival_time").focus();
            return false;
        }
        if(type == '' || type==0) {
            layer.msg('请选择发票类型',{time: 1000});
            $("#type").focus();
            return false;
        }
        if(amount == '') {
            layer.msg('请填写开票金额',{time: 1000});
            $("#amount").focus();
            return false;
        }
        if(description == '') {
            layer.msg('请填写开票内容',{time: 1000});
            $("#description").focus();
            return false;
        }
        if(send_type == '' || send_type==0) {
            layer.msg('请选择寄送方式',{time: 1000});
            $("#send_type").focus();
            return false;
        }
        if(send_type==2 && (send_address=='')){
            layer.msg('请填写地址信息',{time: 1000});
            $("#send_address").focus();
            return false;
        }
        if(type==2 && (taxpayer_id_number == '')) {
            layer.msg('请填写纳税人识别号',{time: 1000});
            $("#taxpayer_id_number").focus();
            return false;
        }
        if(type==2 && (address == '')) {
            layer.msg('请填写地址信息',{time: 1000});
            $("#address").focus();
            return false;
        }
        if(type==2 && (bank == '')) {
            layer.msg('请填写开户行',{time: 1000});
            $("#bank").focus();
            return false;
        }
        if(type==2 && (bank_account == '')) {
            layer.msg('请填写开户行账号',{time: 1000});
            $("#bank_account").focus();
            return false;
        }

        $.post('/admin/order/ajaxSaveApplyBill',
            {
                bill_id: bill_id,
                admin_id: admin_id,
                order_rate: order_rate,
                order_id: order_id,
                company_title: company_title,
                bill_title: bill_title,
                protocol_number: protocol_number,
                is_filing: is_filing,
                type: type,
                item_name: item_name,
                item_type: item_type,
                arrival_time: arrival_time,
                amount: amount,
                description: description,
                send_type: send_type,
                taxpayer_id_number: taxpayer_id_number,
                address: address,
                send_address: send_address,
                bank: bank,
                bank_account: bank_account,
                mobile: mobile
            }, function(data){
                if(data.Code == 999) {
                    layer.alert('操作成功', {
                        skin: 'layui-layer-molv' //样式类名
                        ,closeBtn: 0
                    }, function(){
                        window.location.href = '/admin/order/salesmanOrderList';
                    });
                } else {
                    layer.alert(data.Msg, {
                        skin: 'layui-layer-molv' //样式类名
                        ,closeBtn: 0
                    });
                }
            }, 'json');
    });
</script>